package com.zhinan.controller;

import com.zhinan.common.R;
import com.zhinan.common.SysConstant;
import com.zhinan.entity.SysUser;
import com.zhinan.service.SysUserService;
import com.zhinan.service.impl.SysUserServiceImpl;
import com.zhinan.vo.UserLoginVo;
import com.zhinan.vo.UserRegVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description: TuTu_WorkManager
 * @Author: ZhiNan
 * @Date: 2023-04-10 14:49
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = "系统用户API", description = "系统用户相关操作API")
@RequestMapping("/sysuser")
public class SysUserController {

    @Resource
    private SysUserServiceImpl sysUserService;


    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public R login(UserLoginVo userLoginVo) {
        log.info("登录的用户信息：{}", userLoginVo);
        sysUserService.login(userLoginVo);
        return R.success(SysConstant.LOGIN_SUCCESS);

    }


    @ApiOperation(value = "添加系统用户")
    @PostMapping("/regs")
    public R reg(@Valid UserRegVo userRegVo) {
        log.info("添加的系统用户:{}", userRegVo);
        int result = sysUserService.addUser(userRegVo);
        return R.success(result);

    }

}
